package com.nirvana.factory;

import com.nirvana.item.*;
import com.nirvana.type.ItemType;

import java.util.HashMap;
import java.util.Map;

public class ItemFactory {
    private static final Map<ItemType, CommonItem> commonItemMap = new HashMap<>();

    public static void registerCommonItem(CommonItem commonItem) {
        commonItemMap.put(commonItem.itemType, commonItem);
    }

    public static CommonItem getCommonItem(ItemType type) {
        return commonItemMap.get(type);
    }

    public static AbstractItem createItem(ItemType type) {
        AbstractItem item;
        switch (type) {
            case DefPropertyItem -> item = new DefPropertyItem();
            case ResolvePropertyItem -> item = new ResolvePropertyItem();
            case TableFieldItem -> item = new TableFieldItem();
            default -> throw new RuntimeException();
        }
        item.init();
        return item;
    }
}
